package com.example.demo.domain;

/*
或者使用mybatis-plus的R.ok()或R.fail()
 */

public class MyResponse<T> {
    private Integer code;
    private String msg;
    private T obj;

    public static  <T> MyResponse<T> success(T obj) {
        return new MyResponse<>(CodeEnum.SUCCESS.getCode(), CodeEnum.SUCCESS.getDesc(), obj);
    }

    public static <T> MyResponse<T> success() {
        return new MyResponse<>(CodeEnum.SUCCESS.getCode(), CodeEnum.SUCCESS.getDesc(), null);
    }

    public static <T> MyResponse<T> fail(String msg) {
        return new MyResponse<>(CodeEnum.FAIL.getCode(), msg, null);
    }

    public static <T> MyResponse<T> fail() {
        return new MyResponse<>(CodeEnum.FAIL.getCode(), CodeEnum.FAIL.getDesc(), null);
    }

    public Integer getCode() {
        return code;
    }

    public void setCode(Integer code) {
        this.code = code;
    }

    public String getMsg() {
        return msg;
    }

    public void setMsg(String msg) {
        this.msg = msg;
    }

    public T getObj() {
        return obj;
    }

    public void setObj(T obj) {
        this.obj = obj;
    }

    public MyResponse(Integer code, String msg, T obj) {
        this.code = code;
        this.msg = msg;
        this.obj = obj;
    }

}
